﻿using System;
using System.Collections.Generic;
using System.Text;
using DAL.DateSet.HouseTableAdapters;
using DAL.DateSet;
using DAL;
namespace BLL.Wrapper
{
    public class HouseWrapper : HouseTableAdapter
    {
        public House.HouseDataTable getall()
        {
            return GetData();
        }

        public void addARecord(House.HouseRow row)
        {
            Insert(row.buildingID,row.houseName, row.houseType, row.houseArea, row.housePic, row.houseRemark, row.houseModelSrc, row.houseCreator, row.houseCreateDate);
        }

        public void deleteByID(int id)
        {
            string sql = "delete from House where houseID = " + id.ToString();
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            helper.initOle();
            helper.delete(sql);
        }

        public void updateARecord(House.HouseRow row)
        {
            House.HouseDataTable table = GetData();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (Convert.ToInt32(table.Rows[i]["houseID"]) == row.houseID)
                {
                    table.Rows[i]["buildingID"] = row.buildingID;
                    table.Rows[i]["houseName"] = row.houseName;
                    table.Rows[i]["houseType"] = row.houseType;
                    table.Rows[i]["houseArea"] = row.houseArea;

                    table.Rows[i]["housePic"] = row.housePic;
                    table.Rows[i]["houseRemark"] = row.houseRemark;
                    table.Rows[i]["houseModelSrc"] = row.houseModelSrc;
                    table.Rows[i]["houseCreator"] = row.houseCreator;
                    table.Rows[i]["houseCreateDate"] = row.houseCreateDate;
                    break;
                }
            }
            Update(table);
        }
    }
}
